/**
 * 
 */
package naive;

import java.util.HashMap;

/**
 * @author YR
 * 
 */
public class NaiveImp {
	private static final int START_INDEX = 1;
	private HashMap<Object, Integer> map;

	public HashMap<Object, Integer> getMap() {
		return map;
	}

	/**
	 * 
	 */
	public NaiveImp() {
		map = new HashMap<Object, Integer>();
	}

	public void add(Object o) {
		Integer currentValue=map.get(o);
		if ( currentValue== null) {
			map.put(o, START_INDEX);
		}
		else{
			map.put(o, currentValue+1);
		}	
	}
	public Integer get(Object o){
		return map.get(o);
	}
	
	static class TestMemory {
	     
	    public void details() {
	         
	        int mb = 1024 * 1024;
	         
	        //Getting the runtime reference from system
	        Runtime runtime = Runtime.getRuntime();
	         
	        System.out.println("##### Heap utilization statistics [MB] #####");
	         
	        //Print used memory
	        System.out.println("Used Memory:"
	            + (runtime.totalMemory() - runtime.freeMemory()) / mb);
	 
	        //Print free memory
	        System.out.println("Free Memory:"
	            + runtime.freeMemory() / mb);
	         
	        //Print total available memory
	        System.out.println("Total Memory:" + runtime.totalMemory() / mb);
	 
	        //Print Maximum available memory
	        System.out.println("Max Memory:" + runtime.maxMemory() / mb);
	    }
	}
	
	public static void main(String[] args){
		System.out.println("Naive");
		NaiveImp naive=new NaiveImp();
		
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 1000000-1; j++) {
//				if (j == 82495){
//					System.out.println("");
//				}
				naive.add(j);
//				brick.increment((int) 1);
//				brick.increment((int) 0);
				//82496
			}
		}
//		System.out.println(brick.lookup((int) 0));
//		System.out.println(brick.lookup((int) 1));
		System.out.println(naive.get(333));
		TestMemory tm = new TestMemory();
		tm.details();
	}
}
